package com.dftdla.dao.mapper;

import com.dftdla.dao.pojo.UserGroup;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author 14501
* @description 针对表【user_group】的数据库操作Mapper
* @createDate 2023-11-28 18:18:29
* @Entity generator.domain.UserGroup
*/
@Mapper
public interface UserGroupMapper extends BaseMapper<UserGroup> {
    /**
     * 返回群组所有成员的id列表
     * @param groupId 群组id
     * @return 成员id列表
     */
    @Select("SELECT user FROM user_group WHERE group_id = #{groupId}")
    List<Long> getGroupMembers(Long groupId);

    /**
     * 退出群组
     * @param userId 用户id
     * @param groupId 群组id
     * @return 受影响的行数
     */
    @Delete("DELETE FROM user_group WHERE group_id = #{groupId} AND user = #{userId}")
    int outGroup(Long userId, Long groupId);
}




